#ifndef WIDGETS_DOKERWINDOW_H
#define WIDGETS_DOKERWINDOW_H

#include <QtGui/qsplitter.h>
#include <QtGui/qtabbar.h>
#include <QtGui/qtabwidget.h>

QT_FORWARD_DECLARE_CLASS(QGraphicsItem)
QT_FORWARD_DECLARE_CLASS(QGraphicsRectItem)
QT_FORWARD_DECLARE_CLASS(QGraphicsScene)
QT_FORWARD_DECLARE_CLASS(QGraphicsView)
QT_FORWARD_DECLARE_CLASS(QTabWidget)

class DokerEditor;
class DokerModel;
class DokerView;
class PageObject;
class TextObject;

class DokerTabEditor : public QTabWidget
{
    Q_OBJECT
public:
    explicit DokerTabEditor(QWidget *parent = 0) : QTabWidget(parent) {}
    void highlightTab(int index, bool modified)
    {
        if (modified)
        {
            tabColor = tabBar()->tabTextColor(index);
            tabBar()->setTabTextColor(index, Qt::red);
        }
        else
            tabBar()->setTabTextColor(index, tabColor);
    }
private:
    QColor tabColor;
};

class DokerWindow : public QSplitter
{
    Q_OBJECT
public:
    explicit DokerWindow(DokerModel *model, QWidget *parent = 0);
    DokerEditor *addEditorItem(const QString &fileName, const QString &content = QString());
    DokerTabEditor *editor();
    QGraphicsView *viewer();
    QGraphicsScene *scene();
    void clearViewer();
    void apply();
    void closeTabs();

    void fitWidth();

    void exportToPdf(const QString &fullPdfName);

signals:
    void editorVisibilityChanged(bool visible);
    void viewerVisibilityChanged(bool visible);
    
public slots:
    void addPage(PageObject *page);
    void addText(TextObject *text);
    void viewUnprinted(bool visible);

private slots:
    void closeTab(int index);
    void openEditor(const QString &fileName);
    void update(bool modified);
    void update(const QString &fileName, bool modified);
    
private:
    DokerEditor *findEditorItem(const QString &fileName);
    void editorSetVisible(bool visible);
    void viewerSetVisible(bool visible);

private:
    DokerModel      *m_model;
    QGraphicsScene  *m_scene;
    QGraphicsView   *m_viewer;
    DokerTabEditor  *m_editor;

    int              m_maxPageWidth;
    int              m_originY;

    QGraphicsRectItem*           m_pageItem;
    QList<QGraphicsRectItem*>    m_pages;
    QList<QGraphicsItem*>        m_unprinted;
};

#endif // WIDGETS_DOKERWINDOW_H
